package com.maxd.respository.userMoney;

import com.maxd.model.UserMoney;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

public interface UserMoneyRepository extends Repository<UserMoney, Long> {

    @Query(value = "select * from user_money t where t.user_id=:userId",nativeQuery = true)
    UserMoney selectById(@Param("userId") Long userId);


    @Transactional
    @Modifying
    @Query(value = "update user_money set money=money+:money where user_id=:userId",nativeQuery = true)
    Integer updateMoneyAdd(@Param("userId") Long userId,@Param("money") Double money);

    @Transactional
    @Modifying
    @Query(value = "update user_money set money=money-:money where user_id=:userId",nativeQuery = true)
    Integer updateMoneySub(@Param("userId") Long userId,@Param("money") Double money);


}
